(
    function() {
        var wHeight = getViewportSize().height,
            sHeight = getScrollSize().height,
            playing = false,
            t = null;
        var AutoReader = function(opt) {
            console.log(opt);
            this.playBtn = opt.playBtn;
            this.sTopBtn = opt.sTopBtn;

            var _self = this;

            addEvent(this.sTopBtn, 'click', function() {
                window.scrollTo(0, 0);
                clearInterval(t);
                _self.playBtn.style.backgroundImage = 'url(img/play.png)';
                playing = false;
            })
            addEvent(window, 'scroll', function() {
                _self.sTopBtnShow.call(_self)

            })
            addEvent(this.playBtn, 'click', function() {
                _self.setAutoPlay()
            })
        }
        AutoReader.prototype = {
            setAutoPlay: function() {
                var sTop = getScrollOffset().top,
                    _self = this;
                console.log(this);
                if (sHeight === wHeight + stop) {
                    return
                }
                if (!playing) {
                    t = setInterval(function() {
                        sTop = getScrollOffset().top;
                        // 文档高度=视口高度+滚动高度的时候
                        if (sHeight <= wHeight + sTop) {
                            console.log('还原');
                            clearInterval(t);
                            _self.playBtn.style.backgroundImage = 'url(img/play.png)';
                            playing = false;
                            return
                        } else {
                            window.scrollBy(0, 1);
                            _self.playBtn.style.backgroundImage = 'url(img/pause.png)';

                        }
                    }, 1)
                    playing = true;
                } else {
                    clearInterval(t);
                    _self.style.backgroundImage = 'url(img/play.png)';
                    playing = false;
                }
            },
            sTopBtnShow: function() {
                var sTop = getScrollOffset().top,
                    sTopBtn = this.sTopBtn;
                console.log(this);
                sTopBtn.style.display = sTop ? 'block' : 'none'
            }
        }
        window.AutoReader = AutoReader;
    }

)()